package com.test.frameworkdemo;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by kalshen on 2017/9/11.
 */

public class MainAdapter extends RecyclerView.Adapter<MainAdapter.MainViewHolder> {
    private List<MainBean> mBeans;

    public MainAdapter(List<MainBean> beans) {
        mBeans = beans;
    }

    @Override
    public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_demo, parent, false);
        return new MainViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(MainViewHolder holder, int position) {
        holder.bind(mBeans.get(position));
    }

    @Override
    public int getItemCount() {
        return mBeans.size();
    }

    class MainViewHolder extends RecyclerView.ViewHolder {

        private final TextView mName;

        public MainViewHolder(View itemView) {
            super(itemView);
            mName = (TextView) itemView.findViewById(R.id.tv_name);
        }

        public void bind(MainBean mainBean) {
            mName.setText(mainBean.getName());
        }
    }

    public List<MainBean> getBeans() {
        return mBeans;
    }

    public void setBeans(List<MainBean> beans) {
        mBeans = beans;
    }
}
